package com.solairen.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.FrameLayout;
import android.view.MenuItem;

import androidx.annotation.NonNull;

import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.solairen.myapplication.Pager.HomePager.ConsultationFragment;
import com.solairen.myapplication.Pager.HomePager.HomeFragment;
import com.solairen.myapplication.Pager.HomePager.PersonalFragment;

public class MainActivity extends AppCompatActivity {

    private BottomNavigationView bottomNavigationView;
    private FrameLayout navFragment;
    private HomeFragment homeFragment;
    private ConsultationFragment consultationFragment;
    private PersonalFragment personalFragment;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        bottomNavigationView = findViewById(R.id.bottom_navigation);
        navFragment = findViewById(R.id.navFragment);

        homeFragment = new HomeFragment();
        consultationFragment = new ConsultationFragment();
        personalFragment = new PersonalFragment();

        // 初始页面
        getSupportFragmentManager().beginTransaction().replace(R.id.navFragment, homeFragment).commit();

        // 底部选择栏点击事件监听
        bottomNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                if (item.getItemId() == R.id.navigation_home) {
                    getSupportFragmentManager().beginTransaction().replace(R.id.navFragment, homeFragment).commit();
                } else if (item.getItemId() == R.id.navigation_dashboard) {
                    getSupportFragmentManager().beginTransaction().replace(R.id.navFragment, consultationFragment).commit();
                } else if (item.getItemId() == R.id.navigation_notifications) {

                    getSupportFragmentManager().beginTransaction().replace(R.id.navFragment, personalFragment).commit();
                }
                return true;
            }
        });
    }
}